<?php
/**
 * GeryEngine
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this release in the file LICENSE
 *
 * @copyright  Copyright (c) 2007 Arjen Brouwer
 * @license    New BSD License
 * @author     Arjen Brouwer
 */

class GeryArray extends GeryBaseType {
	
	public function contains($val, $parameters) {
		if ($this->expectParameters(__METHOD__, 'm', $parameters))
			return array_key_exists($parameters[0], $val);
	}
	
	public function reverse($val) {
		return array_reverse($val);
	}
	
	public function size($val) {
		return count($val);
	}
	
	public function keys($val) {
		return array_keys($val);
	}
	
	public function first($val) {
		if (! count($val)) {
			return null;
		} else {
			$keys = array_keys($val);
			return $val[$keys[0]];
		}
	}

	public function last($val) {
		if (! count($val))
			return null;
			
		return end($val);
	}
								
	public function search($val, $parameters) {
		return array_search($parameters[0], $val);
	}

	public function unique($val) {
		return array_unique($val);	
	}

	public function join($val, $parameters) {
		$glue = (count($parameters) > 0)
			? $parameters[0]
			: '';
			
		return join($glue, $val);
	}
	
	public function random($val) {
		$key = array_rand($val);
		return $val[$key];
	}
}
?>